reference operator[] (size_type pos);const_reference operator[] (size_type pos) const;
const-qualified, the function returns a reference to a null character (charT()).1
2
3
4
5
6
7
8
9
10
11
12
13
// string::operator[]
#include <iostream>
#include <string>
int main ()
{
std::string str ("Test string");
for (int i=0; i<str.length(); ++i)
{
std::cout << str[i];
}
return 0;
}
Test string
const-version never throws exceptions (no-throw guarantee).